lucky.extend({
    setter:'js/config',
    component:'js/component',
    admin:'js/admin',
    view:'js/view'
}).define(['setter','admin'],function(exports){
    var setter = lucky.setter
    , admin = lucky.admin
    , view = lucky.view
    , renderView = function(){
        var router = lucky.router()
            , path = router.path
            , ELEM_NAVIGATION = "#main-menu-navigation"
            , menuRouters = $(ELEM_NAVIGATION).find('a.menu-router')

        if (!path.length) path = [''];


        if (path[path.length - 1] === '') {
            //获取菜单栏第一个链接地址
            if(menuRouters.length > 0){
                var firstRouters = admin.correctRouter(menuRouters.eq(0).attr("href")).split('/')
                    , routerIndex = 0;
                $.each(firstRouters,function(index,item){
                    if($.trim(item).length !== 0){
                        path[routerIndex] = item;
                        routerIndex++;
                    }
                });
            }else{
                path[path.length - 1] = setter.views.default;
            }
        }

        view().render(path.join('/')).then(function(res){
            //视图请求成功后的回调
            admin.initMenuActive();
        }).done(function(){
            //视图渲染完毕后的回调
            admin.initAfterRender();
            admin.initMenuEvent();
        });
        //滚动条位置重置
        $(document).scrollTop(0);
    }
    , entryView = function(fn){
        var container = view(setter.container);

        if (admin.pageType === 'console') {
            renderView();
        } else {
            container.render('layout').done(function () {
                renderView();
                admin.initLayout();
                admin.pageType = 'console';
            });
        }
    };

    entryView();

    window.onhashchange = function () {
        entryView();
        //执行 {setter.MOD_NAME}.hash 下的事件
        lucky.event.call(this, setter.MOD_NAME, 'hash({*})', lucky.router());
    };

    exports('index',{
        render: renderView
    });
});